package com.carrot.uaa.common.log;/*
package com.circue.uaa.common.log;


import com.circue.uaa.constant.Oauth2Constants;
import com.circue.uaa.entity.UaaLog;
import com.circue.uaa.infrastructure.service.UaaLogService;
import com.circue.uaa.util.IpAddressUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.*;
import java.time.LocalDateTime;
import java.util.Map;

*/
/**
 * @description:
 * @author: zl
 * @date: 2023/12/25
 *//*

@Component
@AllArgsConstructor
public class LogFilter extends OncePerRequestFilter {

    private final UaaLogService uaaLogService;
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        UaaLog uaaLog=new UaaLog();
        try {
            uaaLog.setExecuteTime(System.currentTimeMillis());
            String clientIp = request.getParameter(Oauth2Constants.CLIENT_IP);
            String grantType = request.getParameter(OAuth2ParameterNames.GRANT_TYPE);
            Map<String, String[]> parameterMap = request.getParameterMap();
            if(clientIp==null){
                clientIp= IpAddressUtil.getClientIpAddress(request);
            }
            String requestURI = request.getRequestURI();
            uaaLog.setClientIp(clientIp);
            uaaLog.setPointUrl(requestURI);
            uaaLog.setRequestParams(parameterMap);
            uaaLog.setGrantType(grantType);
            LogContextUtil.setContext(uaaLog);
            filterChain.doFilter(request,response);

            Authentication clientPrincipal = SecurityContextHolder.getContext().getAuthentication();
            if(clientPrincipal!=null){
                Object principal = clientPrincipal.getPrincipal();
                uaaLog.setAppId(String.valueOf(principal));
            }
            Long startTime = uaaLog.getExecuteTime();
            uaaLog.setExecuteTime(System.currentTimeMillis()-startTime);
            uaaLog.setCreateTime(LocalDateTime.now());
            uaaLogService.save(uaaLog);
            LogContextUtil.resetContext();
        }catch (Exception e){
            e.printStackTrace();
            LogContextUtil.resetContext();
        }
    }
}
*/
